package com.xtoad.ecms.baseinfo;

import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import javax.persistence.EntityManager;

/**
 * 启动类
 *
 * @author xtoad
 * @date 2020/05/29
 */
@SpringBootApplication(scanBasePackages = {"com.xtoad.ecms"})
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    /**
     * 装配JPAQueryFactory
     * Service中直接使用注入：@Autowired JPAQueryFactory queryFactory;
     *
     * @param entityManager JPA接口
     * @return JPAQueryFactory对象
     */
    @Bean
    @Autowired
    public JPAQueryFactory jpaQuery(EntityManager entityManager) {
        return new JPAQueryFactory(entityManager);
    }
}
